import Vue from 'vue'
import VueRouter from 'vue-router'
import point from './modules/point'
import workOrder from './modules/workOrder'
import vm from './modules/vm'
import user from './modules/user'
import sku from './modules/sku'
import policy from './modules/policy'
import order from './modules/order'
import report from './modules/report'
Vue.use(VueRouter)

export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login/login.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404.vue'),
    hidden: true
  },
  {
    path: '/',
    component: () => import('@/views/layout/index.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '帝可得', icon: 'dashboard' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }

]
const asyncRouters = [workOrder, point, vm, user, sku, policy, order, report]
const createRouter = () => new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRouters]
})

const router = createRouter()
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
